// 1. 定义路由常量
import 'package:flutter/material.dart';
import 'package:personinfo/page/CarResource.dart';
import 'package:personinfo/page/CircleOfFriend.dart';
import 'package:personinfo/page/Home.dart';
import 'package:personinfo/page/Person.dart';
import 'package:personinfo/page/PubInfo.dart';
import 'package:personinfo/page/carResource/CarResourceSearch.dart';
import 'package:personinfo/page/carResource/CarResourcesDetail.dart';
import 'package:personinfo/page/carResource/CarSearchHistory.dart';
import 'package:personinfo/page/carResource/SearchResult.dart';
import 'package:personinfo/page/circle/addCircleFriend.dart';
import 'package:personinfo/page/home/MySearchCar.dart';
import 'package:personinfo/page/home/PublishSearchCar.dart';
import 'package:personinfo/page/home/ShoppingCartPage.dart';
import 'package:personinfo/page/home/order/OrderDetail.dart';
import 'package:personinfo/page/home/order/OrderList.dart';
import 'package:personinfo/page/home/searchCar/SelectCarBrand.dart';
import 'package:personinfo/page/home/searchCar/SelectCarInterior.dart';
import 'package:personinfo/page/home/searchCar/SelectCarSeries.dart';
import 'package:personinfo/page/person/Setting.dart';
import 'package:personinfo/page/person/dataStatic.dart';
import 'package:personinfo/page/person/messageNotify.dart';
import 'package:personinfo/page/redirect/Login.dart';
import 'package:personinfo/page/redirect/NotFoundPage.dart';
import 'package:personinfo/page/redirect/SplashScreen.dart';



const String homeRoute = '/';
const String publishSearchCarPage = '/publishSearchCar';
const String mySearchCarPage = '/mySearchCar';
const String selectCarBrandPage = '/selectCarBrand';
const String selectCarSeriesPage = '/selectCarSeries';
const String selectCarInteriorPage = '/selectCarInterior';  //选择内饰



const String circleOfFriend = '/circleFriend';
const String addCircleFriend = '/addCircleFriend';
const String loginPage = '/login';
const String splashPage = '/splash';

const String personPage = '/person';
const String dataStatic = '/dataStatic';
const String messageNotify = "/messageNotify";
const String settingPage = "/setting";

const String notFoundPage = '/notFound';
const String shoppingPage = '/shopping';
const String carResourcePage = '/carResource';
const String carResourceDetailPage = '/carResourceDetail';
const String carSearchHistoryPage = '/carSearchHistory';
const String carResourceSearchPage = '/carResourceSearch';
const String searchResultPage = '/searchResult';


const String pubInfoPage = '/pubInfo';
const String orderListPage = '/orderList';
const String orderDetailPage = '/orderDetail';


// 2. 创建路由配置类
class AppRouter {
  // 单独路由配置表
  static final routes = <String, WidgetBuilder>{
    homeRoute: (context) => const Home(),
    publishSearchCarPage: (context,{arguments}) => PublishSearchCar(arguments:arguments),
    pubInfoPage: (context) => const PubInfo(),

    carResourcePage: (context) => const CarResource(),
    carSearchHistoryPage: (context) => const CarSearchHistory(),
    carResourceSearchPage: (context) => const CarResourceSearch(),
    searchResultPage: (context,{arguments}) =>  SearchResult( arguments: arguments,),
    carResourceDetailPage: (context,{arguments}) => CarResourcesDetail(arguments: arguments),

    circleOfFriend: (context) => const CircleOfFriend(),
    addCircleFriend: (context) => const AddCircleFriend(),
    loginPage:(context) => const Login(),
    splashPage:(context) => const SplashScreen(),

    personPage:(context) => const Person(),
    settingPage:(context) => const Setting(),
    dataStatic:(context) => const DataStatic(),
    messageNotify:(context,{arguments}) => MessageNotify(arguments: arguments),
    notFoundPage:(context) => const NotFoundPage(),
    shoppingPage:(context) =>  const ShoppingCartPage(),
    orderListPage:(context,{arguments}) =>  OrderList(arguments:arguments),
    orderDetailPage:(context,{arguments}) =>  OrderDetail(arguments: arguments),
    mySearchCarPage: (context,{arguments}) => MySearchCar(arguments: arguments),
    selectCarBrandPage: (context,{arguments}) => SelectCarBrand(arguments: arguments),
    selectCarSeriesPage: (context,{arguments}) => SelectCarSeries(arguments: arguments),
    selectCarInteriorPage: (context,{arguments}) => SelectCarInterior(arguments: arguments),
  };

  //白名单
  List url_permission = ["/login"];
  // 路由生成器
  static Route<dynamic>? generateRoute(RouteSettings settings) {

    //统一处理
    final String? name = settings.name;
    final Function? pageContentBuilder = routes[name];
    if (pageContentBuilder != null) {
      if (settings.arguments != null) {
        final Route route = MaterialPageRoute(
            builder: (context) =>
                pageContentBuilder(context, arguments: settings.arguments));
        return route;
      } else {
        final Route route =
        MaterialPageRoute(builder: (context) => pageContentBuilder(context));
        return route;
      }
    }
    return null;
  }
}